package io.renren.modules.lucky.controller;

import io.renren.common.annotation.SysLog;
import io.renren.common.utils.R;
import io.renren.modules.lucky.service.AppStatService;
import org.apache.commons.lang.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("stat/lucky")
public class AppStatController {

    @Autowired
    private AppStatService AppStatService;

    @SysLog("用户每日注册")
    @RequestMapping("appuserachiev/registerInfo")
    @RequiresPermissions("stat:lucky:appuserachiev:registerInfo")
    public Object AppUserRegister(@RequestParam Map<String, Object> params) {

        if (params != null && params.get("dateRange") != null) {
            String dateRange = (String) params.get("dateRange");
            if (StringUtils.isNotBlank(dateRange)) {
                String[] sArr = dateRange.split(",");
                if (sArr.length == 2) {
                    params.put("startDate", sArr[0]);
                    params.put("endDate", sArr[1]);
                }
            }
        }
        Object obj = AppStatService.getAppUserRegisterInfo(params);
        return R.ok().put("page", obj);
    }

    /**
     * @return
     * @获取用户商品偏好信息
     * @author HObOCat
     */
    @RequestMapping("appgoodsachiev/goodlovesInfo")
    @RequiresPermissions("stat:lucky:appgoodsachiev:goodlovesInfo")
    public Object AppGoodsLove(@RequestParam Map<String, Object> params) {
        if (params != null && params.get("dateRange") != null) {
            String dateRange = (String) params.get("dateRange");
            if (StringUtils.isNotBlank(dateRange)) {
                String[] sArr = dateRange.split(",");
                if (sArr.length == 2) {
                    params.put("startDate", sArr[0]);
                    params.put("endDate", sArr[1]);
                }
            }
        }
        Object obj = AppStatService.getAppGoodsLovesInfo(params);
        return R.ok().put("page", obj);
    }

}
